package com.tsunami.utils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

/**
 * @Classname TimeUtil
 * @Description TODO Date 时间工具类
 * @Date 2021-06-22 11:23
 * @Created by lx
 */
public class TimeUtil {

    public static Date addDateMinut(Date date,int m){
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.MINUTE,m);//24小时制
        date = cal.getTime();
        return date;
    }

    /**
     * java8 LocalDateTime格式，String转时间
     * @param dateTime
     * @return
     */
    public static LocalDateTime StringToJava8Time(String dateTime){
        if(StringUtils.isNotEmpty(dateTime)){
            if(dateTime.contains("T")){
                DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
                return LocalDateTime.parse(dateTime,df);
            }else{
                DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                return LocalDateTime.parse(dateTime,df);
            }
        }
        return null;
    }
}
